/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.kproduce.roundcorners.slice;

import com.kproduce.roundcorners.CircleImageView;
import com.kproduce.roundcorners.ResourceTable;
import com.kproduce.roundcorners.RoundImageView;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.element.ShapeElement;

/**
 * MainAbilitySlice
 *
 * @author wp
 * @since 2021-05-21
 */
public class MainAbilitySlice extends AbilitySlice {
    private static final int ROUND_RADIUS = 100;
    private static final int SHAPE_RADIUS = 80;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        CircleImageView circleImageView = (CircleImageView) findComponentById(ResourceTable.Id_CircleImageView);
        circleImageView.createCircleImage(ResourceTable.Media_ic_test);

        RoundImageView roundImageView = (RoundImageView) findComponentById(ResourceTable.Id_RoundImageView);
        roundImageView.setPixelMapToRoundedRect(ResourceTable.Media_ic_test,
            ROUND_RADIUS, ROUND_RADIUS, ROUND_RADIUS, ROUND_RADIUS);

        Component firstComp = findComponentById(ResourceTable.Id_first);
        ShapeElement topLeftElement = (ShapeElement) firstComp.getBackgroundElement();
        topLeftElement.setCornerRadiiArray(new float[]{SHAPE_RADIUS, SHAPE_RADIUS, 0, 0, 0, 0, 0, 0});
        firstComp.setBackground(topLeftElement);

        Component lastComp = findComponentById(ResourceTable.Id_fourth);
        ShapeElement botLeftElement = (ShapeElement) lastComp.getBackgroundElement();
        botLeftElement.setCornerRadiiArray(new float[]{0, 0, 0, 0, 0, 0, SHAPE_RADIUS, SHAPE_RADIUS});
        lastComp.setBackground(botLeftElement);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
